package com.lrkj.back.service.impl;

import java.util.List;
import java.util.Map;

import com.lrkj.back.mapper.TbDictMapper;
import com.lrkj.back.entity.TbDict;
import com.lrkj.back.service.TbDictService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.com.cbons.mamisay.parent.db.api.DBInterface;
import cn.com.cbons.mamisay.parent.exception.DBException;
import cn.com.cbons.mamisay.parent.service.base.ParentServiceImpl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

@Transactional
@Service("dict")
public class TbDictServiceImpl extends ParentServiceImpl<TbDict> implements TbDictService {
    // 自动注解注入
    @Autowired
    private TbDictMapper tbDictMapper;

    @Override
    protected DBInterface<TbDict> getDao() throws DBException {
        return tbDictMapper;
    }

    @Override
    public List<TbDict> findDictList() throws DBException {
        List<TbDict> tdList = tbDictMapper.findDictList();
        return tdList;
    }

    @Override
    public PageInfo<TbDict> findDictSubitems(Map<String, Object> map) throws DBException {
        PageHelper.startPage(Integer.valueOf(map.get("pageNo").toString()),
                Integer.valueOf(map.get("pageSize").toString()));
        List<TbDict> tdList = tbDictMapper.findDictSubitems(map);
        PageInfo<TbDict> page = new PageInfo<TbDict>(tdList);
        return page;
    }

    @Override
    public PageInfo<TbDict> queryTbDictList(Map<String, Object> map) throws DBException {
        PageHelper.startPage(Integer.valueOf(map.get("pageNo").toString()),
                Integer.valueOf(map.get("pageSize").toString()));
        List<TbDict> tdList = tbDictMapper.queryTbDictList(map);
        PageInfo<TbDict> page = new PageInfo<TbDict>(tdList);
        return page;
    }

    @Override
    public TbDict selectByCode(String dictCode) throws DBException {
        return tbDictMapper.selectByCode(dictCode);
    }

    @Override
    public int deleteChildNodes(Integer dictParentid) throws DBException {
        int resultNum = 1;
        try {
            tbDictMapper.deleteChildNodes(dictParentid);
        } catch (Exception e) {
            // TODO Auto-generated catch block
            resultNum = 0;
        }
        return resultNum;
    }

    @Override
    public List<TbDict> findDetailByCode(String dictCode) throws DBException {
        // TODO Auto-generated method stub
        return tbDictMapper.findDetailByCode(dictCode);
    }

}
